package com.taxigang.client.uibinder;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.Session;
import com.taxigang.client.micro.TaxiGangCreator;

public class Invite extends Composite {

	private static InviteUiBinder uiBinder = GWT
	.create(InviteUiBinder.class);

	interface InviteUiBinder extends UiBinder<Widget, Invite> {
	}


	private PopupPanel popupPanel = new PopupPanel(false,true);

	@UiField
	Button okButton;
	@UiField
	Button cancelButton;
	@UiField
	Label invitationTitle;
	@UiField
	TextArea invitationText;

	public Invite(final Command cmd,String title) {
		initWidget(uiBinder.createAndBindUi(this));
		okButton.setText("OK");
		cancelButton.setText(TaxiGangCreator.taxiGangConstants.cancel());

		popupPanel.setTitle("<p><b>"+title+"</b></p>");
		popupPanel.setGlassEnabled(true);
//		popupPanel.setHTML("<p><b>"+title+"</b></p>");

		popupPanel.setWidget(this);
		invitationText.setText(Session.getInstance().getRef());

		okButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				Session.getInstance().setRef(invitationText.getText());
				if (cmd != null){
					cmd.execute();
				}
				popupPanel.hide();
			}
		});
		cancelButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				popupPanel.hide();

			}
		});

	}


	public void show(){
		popupPanel.center();

		popupPanel.show();
	}

}
